package app.fugema.shop.main.order.view;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import app.fugema.shop.main.goods.model.GoodsDetailResult;

import com.base.common.app.LoginUtils;
import com.base.common.utils.OnClickCheckedUtil;
import com.base.common.utils.UIUtils;
import com.base.common.view.base.BaseFragment;
import app.fugema.shop.R;
import app.fugema.shop.databinding.ShoppingCartBottomFmBinding;

import app.fugema.shop.main.order.vm.ShoppingCartVM;

/**
 * 底部的购物车
 */
public class ShoppingCartBottomFragment extends BaseFragment<ShoppingCartBottomFmBinding, ShoppingCartVM>
{

    public static ShoppingCartBottomFragment getInstance()
    {
        ShoppingCartBottomFragment shoppingCartBottomFragment = new ShoppingCartBottomFragment();
        return shoppingCartBottomFragment;
    }

    private GoodsDetailResult dataBean;

    public void setDataBean(GoodsDetailResult dataBean)
    {
        this.dataBean = dataBean;
    }

    @Override
    protected ShoppingCartBottomFmBinding initDataBinding(LayoutInflater inflater, ViewGroup container)
    {
        return DataBindingUtil.inflate(inflater, R.layout.shopping_cart_bottom_fm, container, false);
    }


    @Override
    public void initView() {
        super.initView();
        binding.gService.setOnClickListener(new OnClickCheckedUtil() {
            @Override
            public void onClicked(View view)
            {
                if (!LoginUtils.isLogin()) {
                    UIUtils.showToastSafes("未登录请登录");
                    LoginUtils.loginIn();
                    return;
                }
                UIUtils.showToastSafes("联系客服");
            }
        });
        //购物车
        binding.gCart.setOnClickListener(new OnClickCheckedUtil() {
            @Override
            public void onClicked(View view) {
                if (!LoginUtils.isLogin()) {
                    UIUtils.showToastSafes("未登录请登录");
                    LoginUtils.loginIn();
                    return;
                }
                ShoppingCartActivity.start(view.getContext());
            }
        });
        binding.rtvAddCart.setOnClickListener(new OnClickCheckedUtil() {
            @Override
            public void onClicked(View view) {
                if (!LoginUtils.isLogin())
                {
                    UIUtils.showToastSafes("未登录请登录");
                    LoginUtils.loginIn();
                    return;
                }
                if (dataBean != null)
                {
                    addFragment(ShoppingSpecificationDialog.getInstance(dataBean, false));
                }
            }
        });

        binding.rtvPay.setOnClickListener(new OnClickCheckedUtil() {
            @Override
            public void onClicked(View view) {
                if (!LoginUtils.isLogin())
                {
                    UIUtils.showToastSafes("未登录请登录");
                    LoginUtils.loginIn();
                    return;
                }
                if (dataBean != null)
                {
                    addFragment(ShoppingSpecificationDialog.getInstance(dataBean, false));
                }
            }
        });

    }


}
